import matplotlib.pyplot as plt
import networkx as nx
from matplotlib import rcParams

# 设置字体
rcParams['font.sans-serif'] = ['Microsoft YaHei', 'SimHei', 'Arial Unicode MS', 'sans-serif']
rcParams['axes.unicode_minus'] = False  # 解决负号显示问题

def draw_database_structure_diagram():
    G = nx.DiGraph()

    # 添加节点
    G.add_node("用户", shape='box')
    G.add_node("行程", shape='box')
    G.add_node("目的地", shape='box')
    G.add_node("活动", shape='box')

    # 添加边
    G.add_edges_from([
        ("用户", "行程"),
        ("行程", "活动"),
        ("目的地", "活动"),
        ("用户", "目的地"),
    ])

    pos = nx.spring_layout(G)
    nx.draw(G, pos, with_labels=True, node_size=3000, node_color='lightgreen', font_size=10, font_weight='bold', edge_color='gray')
    plt.title('图3.1_数据库表结构示意图')
    plt.savefig('图3.1_数据库表结构示意图.png')
    plt.close()

if __name__ == "__main__":
    draw_database_structure_diagram() 